﻿using System;
using System.Linq.Expressions;
using NHibernate.Expression.Extensions.Helpers;
using NHibernate.SqlCommand;
using NHibernate.Criterion;

namespace NHibernate.Expression.Extensions {
    public static class DetachedCriteriaExtensions {
        public static DetachedCriteria CreateAlias<T>(this DetachedCriteria dc, Expression<Func<T, object>> property,
                                                      string alias) {
            return dc.CreateAlias(property.MemberName(), alias);
        }

        public static DetachedCriteria CreateAlias<T>(this DetachedCriteria dc, Expression<Func<T, object>> property,
                                                      string alias, JoinType joinType) {
            return dc.CreateAlias(property.MemberName(), alias, joinType);
        }

        public static DetachedCriteria CreateAlias<T>(this DetachedCriteria dc, string prefix,
                                                      Expression<Func<T, object>> property,
                                                      string alias) {
            return dc.CreateAlias(string.Format("{0}.{1}", prefix, property.MemberName()), alias);
        }

        public static DetachedCriteria CreateAlias<T>(this DetachedCriteria dc, string prefix,
                                                      Expression<Func<T, object>> property,
                                                      string alias, JoinType joinType) {
            return dc.CreateAlias(string.Format("{0}.{1}", prefix, property.MemberName()), alias, joinType);
        }
    }
}